﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace Linn.Controls {
    public abstract class Control {
        protected Control(string placeholderText, string tag, string title) {
            this.PlaceholderText = placeholderText;
            this.Tag = tag;
            this.Title = title;
        }
        public abstract ContentType ControlType { get; }
        public string PlaceholderText { get; private set; }
        public string Tag { get; private set; }
        public string Title { get; private set; }
        public object Value { get; set; }
    }

    public class ControlCollection : IEnumerable<Control> {
        private List<Control> _controls;

        public ControlCollection() {
            _controls = new List<Control>();
        }

        public ControlCollection(int capacity) {
            _controls = new List<Control>(capacity);
        }

        public int Count { get { return _controls.Count; } }

        public Control this[int index] { get { return _controls[index]; } }

        public Control this[string tag] {
            get {
                foreach(Control ctrl in _controls) {
                    if(ctrl.Tag == tag) {
                        return ctrl;
                    }
                }

                return null;
            }
        }

        public void Add(Control control) {
            _controls.Add(control);
        }

        public IEnumerator<Control> GetEnumerator() {
            return _controls.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator() {
            return GetEnumerator();
        }
    }
}
